<?php
/**
 * Created by PhpStorm.
 * User: tavete
 * Date: 23/01/15
 * Time: 19:39
 */

namespace CAI\HistoricoBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Doctrine\ORM\EntityRepository;

class PersonaType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('personas_nombre', 'text')
            ->add('personas_apellido', 'text')
            ->add('pais', 'entity', array('class' => 'CAIHistoricoBundle:Pais',
                'query_builder' => function(EntityRepository $er) {
                    return $er->createQueryBuilder('p')
                        ->orderBy('p.paises_nombre', 'ASC');
                }));
    }

    public function getName()
    {
        return 'persona';
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'CAI\HistoricoBundle\Entity\Persona',
        ));
    }
}